package com.jy.framework.base;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang.builder.ToStringBuilder;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Author JuiceYan
 * @Description 公共属性
 * @Date 2018-12-15
 **/
@Data
public class BaseEntity implements Serializable {
    /**
     * 主键id
     */
    @TableId
    @ApiModelProperty(value = "主键")
    protected Serializable id;
    /**
     * 名称
     */
    @ApiModelProperty(value = "名称")
@Excel(name = "名称")
    protected String name;
    /**
     * 创建人
     */
    @ApiModelProperty(value = "创建人")
    @TableField(fill = FieldFill.INSERT)
    protected Long createBy;
    /**
     * 创建时间 yyyyMMdd HH:mm:ss
     */
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @TableField(fill = FieldFill.INSERT)
    protected Date createTime;
    /**
     * 更新人
     */
    @ApiModelProperty(value = "更新人")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    protected Long updateBy;
    /**
     * 更新时间 yyyyMMdd HH:mm:ss
     */
    @ApiModelProperty(value = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    protected Date updateTime;
    /**
     * 备注
     */
    @ApiModelProperty(value = "备注")
@Excel(name = "备注")
    protected String remark;
    /**
     * 是否删除
     */
    @ApiModelProperty(value = "是否删除")
    @TableLogic
    @TableField("del_flag")
    protected Integer delFlag;
    /**
     * 请求参数
     */
    @ApiModelProperty(value = "请求参数")
    @TableField(exist = false)
    protected Map<String, Object> params;

    public Map<String, Object> getParams() {
        if (params == null) {
            params = new LinkedHashMap<>();
        }
        return params;
    }

    public void setParams(Map<String, Object> params) {
        this.params = params;
    }

    public BaseEntity(Serializable id) {
        this.id = id;
    }

    public BaseEntity() {
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
